package com.itzhoun;

import java.util.ArrayList;

/**
 * @author 周楠
 * @Date 2023/01/22/下午 5:14
 */
public class Composite implements Component{

    private ArrayList<Component> children = new ArrayList<Component>();

    @Override
    public void add(Component component) {
        children.add(component);
    }

    @Override
    public void remove(Component component) {
        children.remove(component);

    }

    @Override
    public Component getChild(int i) {
        return children.get(i);
    }

    @Override
    public void operation() {
        for (Component child : children) {
            child.operation();
        }

    }
}
